<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of address_model
 *
 * @author hassanali
 */
class store_model extends cms_model {

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->table = 'stores';
        $this->select = array('stores.*', 'user.username', 'user.create_date as ucreate');
        $this->join = array(
            'user' => 'user.id = stores.owner_id'
        );
    }

    function get_stores($where = array()) {
        $stores = $this->get($where);
        $this->load->model('store_details_model', 'stdetails');
        $nodata = array();
        $index = 0;
        foreach ($stores as $store) {
            $details = $this->stdetails->get(array('store_id' => $store->id));
            if (count($details) > 0) {
                $return['storedetails'][$store->id] = $details;
            } else {
                $nodata[] = $index;
            }
            $index++;
        }
        
        if(count($nodata) > 0){
            foreach($nodata as $nd => $va)
                unset ($stores[$va]);
        }
        $return['stores'] = $stores;
        return $return;
        
    }

}

?>
